package com.itheima.project_cloth.controller;

import com.itheima.project_cloth.pojo.OrderConsumer;
import com.itheima.project_cloth.pojo.Result;
import com.itheima.project_cloth.service.OrderConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/orderConsumers")
public class OrderConsumerController {
    @Autowired
    private OrderConsumerService orderConsumerService;

    @GetMapping
    public Result SelectOrderConsumerByTime(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime time,
                                            String phoneNumber, String address, String price
    ){
        List<OrderConsumer> orderConsumerList = orderConsumerService.SelectOrderConsumerByTime(time, phoneNumber, address, price);

        return Result.success(orderConsumerList);
    }


    @PostMapping
    public Result InsertOrderConsumer(@RequestBody OrderConsumer orderConsumer){
        orderConsumerService.InsertOrderConsumer(orderConsumer);
        return Result.success();
    }


    @DeleteMapping("{id}")
    public Result DeleteOrderConsumerById(@PathVariable List<Integer> id){
        orderConsumerService.DeleteOrderConsumerById(id);
        return Result.success();
    }
    @GetMapping("/update/{id}")
    public Result UpdateOrderConsumerByIdselect(@PathVariable Integer id){
        OrderConsumer orderConsumer= orderConsumerService.UpdateOrderConsumerByIdselect(id);
        return Result.success(orderConsumer);
    }
    @PutMapping
    public Result update(@RequestBody OrderConsumer orderConsumer){
        orderConsumerService.UpdateOrderConsumerById(orderConsumer);
        return Result.success();
    }

    @GetMapping("/name/{name}")
    public Result SelectOrderConsumerByName(@PathVariable String name){
        log.info("根据订单号查询订单信息 {}",name);
        OrderConsumer oc = orderConsumerService.SelectOrderConsumerByName(name);
        return Result.success(oc);
    }

    @GetMapping("/cid/{consumerId}")
    public Result SelectOrderConsumerByConsumer(@PathVariable Integer consumerId){
        log.info("根据消费者id查询订单信息 {}",consumerId);
        List<OrderConsumer> oc = orderConsumerService.SelectOrderConsumerByConsumer(consumerId);
        return Result.success(oc);
    }

    @GetMapping("/cad/{address}")
    public Result SelectOrderConsumerByAddress(@PathVariable String address){
        log.info("根据消费者地址查询订单信息 {}", address);
        List<OrderConsumer> oc = orderConsumerService.SelectOrderConsumerByAddress(address);
        return Result.success(oc);
    }

    @GetMapping("/{name}")
    public Result select(@PathVariable String name) {
        log.info("根据订单号查询：{}",name);
        OrderConsumer ocon = orderConsumerService.select(name);
        return Result.success(ocon);
    }



}
